@include('admin.public.head')

<script type="text/javascript" src="{{ URL::asset('./admin/js/area.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('./admin/js/colResizable-1.6.js') }}"></script>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/city.min.js"></script>

<div class="ibox-title">
    <h5>門店添加</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">

        <div class="form-group">
            <label class="col-sm-3 control-label">門店名称：</label>
            <div class="col-sm-3">
                <input type="text" name="store_name" class="form-control" placeholder="門店名称" value="{{$result->store_name??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">門店地区：</label>
            <div class="col-sm-1">
                <select class="form-control" style="width:100px;" id="province" name="province"></select>
            </div>
            <div class="col-sm-1">
                <select class="form-control" style="width:100px;" id="city" name="city" ></select>
            </div>
            <div class="col-sm-1">
                <select class="form-control" style="width:100px;" id="county" name="county"></select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">門店地址：</label>
            <div class="col-sm-3">
                <input type="text" name="store_address" class="form-control" placeholder="門店地址" value="{{$result->store_address??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <a class="btn btn-primary do" type="submit">操作</a>
                <a href="/store" class="btn btn-primary" >返回門店列表</a>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    var province = "{{$result->province??''}}";
    var city = "{{$result->city??''}}";
    var area = "{{$result->area??''}}";
    var id = "{{$result->id??''}}";

    var s=["province","city","county"];

    if(id == ''){
        var opt0 = [];
    }else{
        var opt0 = [province,city,area];
    }

    _init_area();
</script>
<script>
    var synopsis_content = UE.getEditor('synopsis');

    $('.do').click(function(){
        var form = new FormData();

        var store_name = $('input[name="store_name"]').val();
        var store_address = $('input[name="store_address"]').val();
        var id = $('input[name="id"]').val();
        var province = $('select[name="province"] option:selected').val();
        var city = $('select[name="city"] option:selected').val();
        var county = $('select[name="county"] option:selected').val();

        form.append("store_name", store_name);
        form.append("store_address", store_address);
        form.append("province", province);
        form.append("city", city);
        form.append("area", county);

        form.append("id", id);

        $.ajax({
            type: 'POST',
            url: '/store_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        //window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });

</script>
